<%--
  Created by IntelliJ IDEA.
  User: 18383
  Date: 2023/3/9
  Time: 19:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="static/plugins/bootstrap-3.4.1/css/bootstrap.min.css">
    <style>
        body {
            background-color: rgb(240, 240, 242);
        }

        .item-book {
            background: white;
            height: 330px;
            margin-bottom: 18px;
            border-radius: 5px;
            padding-top: 8px;
        }

        .book-avatar {
            width: 100%;
            height: 230px;
        }

        .book-avatar img {
            width: 100%;
            height: 100%;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
        }

        .book-info {
            padding: 12px 18px;
        }

        .book-name {
            font-size: 18px;
            font-weight: 600;
            overflow: hidden;
            height: 25px;
            /*white-space: nowrap;*/
            /*text-overflow: ellipsis;*/
        }

        .author {
            height: 24px;
            line-height: 24px;
            color: #aaa;
            overflow: hidden;
        }

        .price {
            line-height: 26px;
            overflow: hidden;
            font-size: 16px;
            position: relative;
            height: 36px;

            color: #c30;
            float: left;
            font-weight: bold;
            margin-right: 12px;
        }

        a, a:hover {
            text-decoration: none;
            color: #333333;
        }
    </style>
</head>
<body>
<%
    if(session.getAttribute("user_id")==null){
        String account = null;
        String password = null;
        // 获取cookie信息，验证用户是否已经登录
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("account")) {
                    account = cookie.getValue();
                }
                if (cookie.getName().equals("password")) {
                    password = cookie.getValue();
                }
            }
        }
        // 如果username 和 password 存在，就执行自动登录
        //注意用户打开login.jsp 是get请求，所以这里的请求转发也是一个get请求，login里也需要重写doGet方法，处理get请求
        if (account != null && password != null) {
            request.getRequestDispatcher("/user?m=login&account=" + account + "&password=" + password).forward(request, response);
        }
    }
%>
<jsp:include page="layout/nav.jsp"></jsp:include>
<div class="container">
    <c:forEach items='${requestScope.bookList}' var="book">
        <div class="col-md-3">
            <div class="item-book">
                <div class="book-avatar">
                    <a href="/book?m=detail&bid=${book.id}"><img src="${book.cover}"></a>
                </div>
                <div class="book-info">
                    <div class="book-name">
                        <a href="/book?m=detail&bid=${book.id}">${book.name}</a>
                    </div>
                    <div class="author">
                            ${book.author}
                    </div>
                    <div class="price">
                        <span class="sign">¥</span>
                        <span>${book.price}</span>
                    </div>
                </div>
            </div>
        </div>
    </c:forEach>
</div>

<script src="static/js/jquery-3.6.3.min.js"></script>
<script src="static/plugins/bootstrap-3.4.1/js/bootstrap.min.js"></script>
<script src="static/plugins/jqueryvalidate/jquery.validate.js"></script>
<script src="static/plugins/jqueryvalidate/messages_zh.js"></script>
<script src="static/js/jsEmail.js"></script>
<script src="static/js/registerForm.js"></script>

</body>
</html>
